#include "FoGGEDEF.h"
#include "aTerminal.h"
#include "MemoryLogger.h"
namespace _FOGGE_
{
	namespace _UTIL_
	{

		aTerminal::aTerminal(void)
		{
			m_ptrNextTerm=NULL;
		}

		aTerminal::~aTerminal(void)
		{
			RemoveTerminalAtChain();
			
		}
		void aTerminal::Write( LPCTSTR str )
		{

			Write_Implement(str);
			
			if(m_ptrNextTerm)
				m_ptrNextTerm->Write(str);

		}
		void aTerminal::Flush()
		{
			Flush_Implement();

			if(m_ptrNextTerm)
				m_ptrNextTerm->Flush();

		}

		//! attach logger to end of logchain
		void aTerminal::AttachTerminalToChain(aTerminal* ptrTerm)
		{
			assert(ptrTerm->m_ptrNextTerm==NULL&&"AttachTerminalToChain_ cant attach a terminal that have child");
			if(m_ptrNextTerm)
				m_ptrNextTerm->AttachTerminalToChain(ptrTerm);
			else
				m_ptrNextTerm= ptrTerm;
		}

		void aTerminal::RemoveTerminalAtChain()
		{
			if(m_ptrNextTerm)
			{
				m_ptrNextTerm->RemoveTerminalAtChain();
				foDELETE(m_ptrNextTerm);
			}
			
				
		
		}


	}
}